/**
 * /   对应模板文件upload.html    /
 * upload 跳转上传页面                   uploadUrl: prefix + "/upload",
 * uploadFile 导入文件
 * downloadExample 下载模板
 * //////////////////////
 * @type {{upload: cy.upload, uploadFile: cy.uploadFile, downloadExample: cy.downloadExample}}
 */

var cy = {
    importUrl:'',
    upload: function () {
        $.modal.open("导入" + $.table._option.modalName, $.table._option.uploadUrl);
    },
    uploadFile: function () {
        var uploadInput = $('#formUpload')[0].file;
        var uploadInputValue = uploadInput.value;
        console.log(uploadInputValue);
        if (uploadInputValue == '') {
            $.modal.alertWarning("请选择文件");
            return false;
        }

        var formData = new FormData($('#formUpload')[0]);
        console.log(formData);
        $.ajax({
            url: cy.importUrl,
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function (result) {
                $.operate.successCallback(result);
            }
        });
    },
    downloadExample: function () {
        $("#downloadExample").bind("click", function () {
            $.post(
                prefix + "/exportExample",
                '',
                function (result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true;
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                });
        })
    }
};

cy.downloadExample();
$("#uploadCommon").bind("click",function(){
    $("#file").click();
});



// /**
//  * 导入
//  */
// @GetMapping("/upload")
// public String upload()
// {
//     return prefix + "/upload";
// }
//
// /**
//  * 模板下载
//  */
// @PostMapping("/exportExample")
// 	@ResponseBody
// public AjaxResult exportExample()
// {
//     List<StudentManage> list = new ArrayList<>();
//     StudentManage studentManage = new StudentManage();
//     studentManage.setStuName("测试名称");
//     studentManage.setStuNo("20191000");
//     studentManage.setHasPractice(1);
//     studentManage.setHasWorkRoom(1);
//     studentManage.setPracticeStatus("0");
//     studentManage.setStuClass("软件0881");
//     list.add(studentManage);
//     ExcelUtil<StudentManage> util = new ExcelUtil<StudentManage>(StudentManage.class);
//     return util.exportExcel(list, "学生数据");
// }
//
//
// 	@PostMapping("/importData")
// 	@ResponseBody
// public AjaxResult importData(MultipartFile file) throws Exception
// {
//     String filename = file.getOriginalFilename();
//     if (filename.contains(".xls")||filename.contains(".xlsx")) {
//         ExcelUtil<StudentManage> util = new ExcelUtil<StudentManage>(StudentManage.class);
//         List<StudentManage> userList = util.importExcel(file.getInputStream());
//         studentManageService.importStudent(userList);
//         return AjaxResult.success("导入成功！");
//     }else{
//         return error("请导入正确的文件格式！");
//     }
//
// }